package com.whsr.readservice.controller;

import com.github.pagehelper.PageInfo;
import com.whsr.readservice.service.ChapterService;
import com.whsr.readservice.util.ResultUtil;
import com.whsr.readservice.vo.Chapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/server/chapter")
public class ChapterController {

    @Autowired
    private ChapterService chapterService;

    /**
     * 根据书号 查询作品目录列表
     * @param bookId
     * @return
     */
    @RequestMapping(value = "/getChapters/{bookId}/{pageNo}/{pageSize}",method = RequestMethod.GET)
    public PageInfo<Chapter> getChapters(@PathVariable Integer bookId, @PathVariable Integer pageNo, @PathVariable Integer pageSize){
        return chapterService.getChaptersByBookId(bookId, pageNo, pageSize);
    }

    /**
     * 根据书号 查询作品目录列表
     * @param bookId
     * @return
     */
    @RequestMapping(value = "/queryChsByApp/{bookId}",method = RequestMethod.GET)
    public Map<String, Object> getChapters(@PathVariable Integer bookId){
        try {
            return chapterService.getChaptersByApp(bookId);
        } catch (Exception e) {
            return ResultUtil.getResultByError();
        }
    }
}
